<?php

namespace app\common\model;

use think\cache\driver\Redis;
use think\facade\Env;

class RedisService
{
    protected $redis;
    protected $key;
    function __construct()
    {
        $params =[
            'host' => Env::get('REDIS.HOST', '127.0.0.1'),
            'port' => Env::get('REDIS.PORT', 6379),
            'password' => Env::get('REDIS.PASSWORD', '123456'),
            'select' => Env::get('REDIS.select', 0),
        ];
        $redis = new Redis($params);
        $this->redis = $redis->handler();
    }

    //不用ins 名称会冲突
    static $stance = false;

    /**
     * @return bool|RedisService
     */
    public static function instance()
    {
        if(!self::$stance){
            $obj = new self();
            self::$stance = $obj->redis;
        }
        return self::$stance;
    }

    public function getRedis()
    {
        return $this->redis;
    }
}